﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace SkiTracker.Converter
{
    public class ColorToColorWithAlphaChannelConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Color)
            {
                var color = (Color) value;
                if (color == Color.FromArgb(0, 0, 0, 0)) color = App.CurrentApp.AccentColor;

                if (parameter != null)
                {
                    try
                    {
                        color = Color.FromArgb(
                            byte.Parse((string)parameter, NumberStyles.HexNumber),
                            color.R, color.G, color.B);
                    }
                    catch
                    {
                    }
                }
                return color;
            }
            return DependencyProperty.UnsetValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
